//
//  SenderFactory.m
//  NetImager
//
//  Created by li hongliang on 10-9-6.
//  Copyright 2010 sweet-home. All rights reserved.
//

#import "SenderFactory.h"
#import "DoubanSender.h"
#import "FlickerSender.h"
#import "TwitterSender.h"
#import "FacebookSender.h"

@interface SenderFactory()

@property (nonatomic, retain) id<SenderDelegate> sender;


@end


@implementation SenderFactory

@synthesize sender;

+(id) senderWithSiteKeyStr:(NSString *)siteKeyStr delegate:(id)target
{
	if([siteKeyStr caseInsensitiveCompare:@"douban"] == 0) {
		return [[[DoubanSender alloc] initWithSite:siteKeyStr delegate:target] autorelease];
	}
	else if([siteKeyStr caseInsensitiveCompare:@"flicker"] == 0)
	{
		return [[[FlickerSender alloc] initWithSite:siteKeyStr delegate:target] autorelease];
	}
	else if([siteKeyStr caseInsensitiveCompare:@"twitter"] == 0)
	{
		return [[[TwitterSender alloc] initWithSite:siteKeyStr delegate:target] autorelease];
	}
	else if([siteKeyStr caseInsensitiveCompare:@"facebook"] == 0)
	{
		return [[[FacebookSender alloc] initWithSite:siteKeyStr delegate:target] autorelease];
	}
	else {
		return nil;
	}
}

- (void) sendTest:(NSString *)siteKeyStr image:(UIImage *)image delegate:(id)target
{
	self.sender = [SenderFactory senderWithSiteKeyStr:siteKeyStr delegate:target];
	if(self.sender != nil){
		if([self.sender conformsToProtocol:@protocol(SenderDelegate)])
		{
			if([self.sender respondsToSelector:@selector(picSend:)])
			{
				[self.sender picSend: image];
			}
		}
	}
}

- (void) dealloc {
	[self.sender release];
	[super dealloc];
}

@end
